package team.seekers.hula.course.resource.examSubmit.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;
import team.seekers.hula.common.annotation.ApiResponseBody;
import team.seekers.hula.auth.service.MindUtils;
import team.seekers.hula.course.resource.examSubmit.entity.dto.ExamRecordCreateDTO;
import team.seekers.hula.course.resource.examSubmit.entity.dto.ExamRecordDTO;
import team.seekers.hula.course.resource.examSubmit.entity.vo.ExamRecordInfoVO;
import team.seekers.hula.course.resource.examSubmit.service.ExamRecordService;

import java.util.List;
import java.util.Map;

/**
 * date: 2022/5/9 17:46
 *
 * @author GH
 * QQ 1124813753
 */
@Controller
@ApiResponseBody
@RequestMapping("/exam/record")
public class ExamRecordController {

    @Autowired
    private ExamRecordService examRecordService;

    /**
     * 进入测试并生成记录
     * @param json examId测试id
     */
    @PostMapping("/create")
    public String createExamSubmission(@RequestBody Map<String,Object> json) {
        String examId = (String) json.get("examId");
        return examRecordService.participateExam(examId, MindUtils.getUserId(),"realIp");
    }



    /**
     * 提交测试并统计得分
     * @param createDTO 提交测试信息
     */
    @PostMapping("/submit")
    public void submitExamSubmission(@RequestBody ExamRecordCreateDTO createDTO) {
        // 增补
        createDTO.setIpv4("userSessionDTO");
        examRecordService.examSubmit(createDTO);
    }

    /**
     * 用户根据测试id查询自己的测试记录
     * @param examId 测试id
     */
    @GetMapping("/list")
    public List<ExamRecordDTO> list(@RequestParam String examId) {
        return examRecordService.list(examId,MindUtils.getUserId());
    }

    /**
     * 用户根据测试记录id查询某次测试的状态和提交记录
     * @param examRecordId 测试记录id
     */
    @GetMapping("/info")
    public ExamRecordInfoVO queryExamRecordInfo(@RequestParam String examRecordId) {
        return examRecordService.queryExamRecordInfo(examRecordId);
    }


}
